<admintpl file="header"/>

<script src="__PUBLIC__/js/common.js"></script>

</head>
<body>
<div class="wrap">
    <form method="post" class="form-horizontal " id="myform"  action="{:U('Admin/NewsSet/editAdminPost')}">
        <div class="containerr">

            <div class="left">设置管理员</div>
            <div class="span3">
                <input type="hidden" name="column_id" id="column_id" value="<?php echo $column_id;?>">
                <input type="hidden" name="admin_hidden_ids" id="admin_hidden_ids"  value="<?php echo $arr_admin_ids ? implode(',',$arr_admin_ids).',' : '';?>">
                <input type="text"  style="width: 556px;" name="administrators" id="administrator" readonly="readonly" value="<?php echo $arr_usernames ? implode(',',$arr_usernames).',' : '';?>">
            </div>

        </div>

        <div class="control-group" style="margin-top: 50px;">
            <label class="span1 control-label" style="width: 90px;"></label>
            <div class="span3">
                <foreach name="admin_infos" key="admin_key" item="admin_value">
                    <input  admin_name="{$admin_value['username']}" name="admin_checkbox"  type="checkbox" value="{$admin_value['admin_id']}" <?php if(in_array($admin_value['admin_id'],$arr_admin_ids)) echo 'checked="checked"';?>/>{$admin_value['username']}<br/>
                </foreach>
            </div>
        </div>


        <div class="form-actions" style="padding-left:260px;">
            <a class="btn btn-primary" id="ajaxform">提 交</a>
            &nbsp;&nbsp;<a class="btn" id="ajaxback">{:L('BACK')}</a>
        </div>
    </form>
</div>

<script type="text/javascript" src="__PUBLIC__/js/content_addtop.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript"
        src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script type="text/javascript">
    $(function(){
        $("[name='admin_checkbox']").click(function(){
            var admin_id = $(this).val();
            var admin_name = $(this).attr('admin_name');

            var admin_hidden_ids = $("#admin_hidden_ids").val();
            var admin_values = $("#administrator").val();

            var ids_arr = admin_hidden_ids.split(",");
            var values_arr = admin_values.split(",");


            if(ids_arr.indexOf(admin_id) == '-1'){

                admin_hidden_ids+=admin_id+',';
                admin_values+=admin_name+',';
                $("#administrator").val(admin_values);
                $("#admin_hidden_ids").val(admin_hidden_ids);
            }else{

                $.each(ids_arr,function(index,item){
                    if(item==admin_id){
                        ids_arr.splice(index,1);
                        values_arr.splice(index,1);
                    }
                })
                admin_hidden_ids = ids_arr.join(",");
                admin_values = values_arr.join(",");
                $("#administrator").val(admin_values);
                $("#admin_hidden_ids").val(admin_hidden_ids);
            }
        })
    })


    // ajax 提交表单
    $(document).ready(function(){
        $("#ajaxform").click(function(){    // 提交按钮触发事件
            var tourl = $("#myform").attr("action");    // 获取 表单的 提交地址
            var column_id = $("#column_id").val();
            var admin_hidden_ids = $("#admin_hidden_ids").val();

            $.post(tourl,{admin_hidden_ids:admin_hidden_ids,column_id:column_id},function(result){
                if(result == '1'){
                    var msg = '编辑成功';
                }else{
                    var msg = '编辑失败';
                }

                parent.layer.msg(msg,{time:2000},1,function(a){

                });
                setTimeout(function(){
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                }, 1000);
            });
        });
        $("#ajaxback").click(function(){
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.close(index);
        });
    });
</script>
</body>
</html>